package org.ceteca.explica.client.management;

import org.ceteca.javaglade.handlers.GenericHandler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class LotOutItemListener extends GenericHandler {
	private TreeItem item;
	private Text text;
	
	public LotOutItemListener(Text text) {
		this.text = text;
		this.item = null;
	}
	
	public LotOutItemListener(TreeItem item, Text text) {
		this.item = item;
		this.text = text;
	}
	
	public void setItem(TreeItem item) {
		this.item = item;
	}

	
	public void on_focusLost(Event event) {
		if (item != null)
			item.setText(2, text.getText());
		text.setVisible(false);
	}
	
	public void on_keyPressed(Event event) {
		System.out.println("Pulsada tecla "
				+ event.keyCode);
		switch (event.keyCode) {
			case SWT.CR:
				if (item != null)
					item.setText(2, text.getText());
			case SWT.KEYPAD_MULTIPLY:
				if (item != null)
					item.setText(2, text.getText());
			case SWT.TAB:
				if (item != null)
					item.setText(2, text.getText());
			case SWT.ESC:
				text.setVisible(false);
				break;
		}
	}
}
